package com.ysg.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5工具类
 */
public class YMD5Utils {

	public static String get(String s) {
		MessageDigest md5_dig;
		try {
			md5_dig = MessageDigest.getInstance("md5");
		} catch (NoSuchAlgorithmException e) {
			return "";
		}
		byte[] bytes = s.getBytes();
		md5_dig.update(bytes);
		return byte2hex(md5_dig.digest());
	}

	private static String byte2hex(byte[] bytes) {
		StringBuffer buf = new StringBuffer("");
		for (int i = 0; i < bytes.length; i++) {
			String t = Integer.toHexString(bytes[i] >= 0 ? bytes[i]: (bytes[i] + 256));
			if (t.length() < 2){
				t = "0" + t;
			}
			buf.append(t.toLowerCase());
		}
		return buf.toString();
	}

}
